package com.sk.sourcecircle.dialog;

import android.app.DialogFragment;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.RadioButton;

import com.sk.sourcecircle.R;
import com.sk.sourcecircle.callback.MyCallBack;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

/**
 * Created by sk on 2017/12/25.
 */

public class CancelOrderFragment extends DialogFragment {

    @BindView(R.id.close)
    ImageView close;
    @BindView(R.id.reason1)
    RadioButton reason1;
    @BindView(R.id.reason2)
    RadioButton reason2;
    @BindView(R.id.reason3)
    RadioButton reason3;
    Unbinder unbinder;
    private MyCallBack myCallBack;

    public MyCallBack getMyCallBack() {
        return myCallBack;
    }

    public void setMyCallBack(MyCallBack myCallBack) {
        this.myCallBack = myCallBack;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        int style = android.support.v4.app.DialogFragment.STYLE_NO_TITLE, theme = 0;
        setStyle(style, theme);
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.dialog_cancel_order, container, false);
        unbinder = ButterKnife.bind(this, view);
        return view;
    }

    public void onStart() {
        super.onStart();
        getDialog().getWindow().getAttributes().windowAnimations = R.style.dialogAnim;
        getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(Color.parseColor("#00000000")));
        WindowManager.LayoutParams layoutParams = getDialog().getWindow().getAttributes();
        layoutParams.gravity = Gravity.BOTTOM;
        layoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
        getDialog().getWindow().setAttributes(layoutParams);
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }

    @OnClick({R.id.close, R.id.reason1, R.id.reason2, R.id.reason3})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.close:
                dismiss();
                break;
            case R.id.reason1:
                dismiss();
                myCallBack.cancelOder("");
                break;
            case R.id.reason2:
                dismiss();
                myCallBack.cancelOder("");
                break;
            case R.id.reason3:
                dismiss();
                myCallBack.cancelOder("");
                break;
        }
    }
}
